package top.mschen.blog.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
public class SwaggerConfig {

    @Bean
    public Docket userDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("用户模块")
                .apiInfo(apiInfo())
                .select()
//                .apis(RequestHandlerSelectors.withClassAnnotation(ApiOperation.class))//只有这个注解的接口生效
                .apis(RequestHandlerSelectors.basePackage("top.mschen.blog.controller.user"))//这个包下的
                .paths(PathSelectors.regex("/users.*"))//只有这个路劲的
                .build();
    }

    @Bean
    public Docket articleDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("文章模块")
                .apiInfo(apiInfo())
                .select()
//                .apis(RequestHandlerSelectors.withClassAnnotation(ApiOperation.class))//只有这个注解的接口生效
                .apis(RequestHandlerSelectors.basePackage("top.mschen.blog.controller.user"))//这个包下的
                .paths(PathSelectors.regex("/users.*"))//只有这个路劲的
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Spring Boot中使用Swagger2构建RESTful APIs \nSpring Boot中使用Swagger2构建RESTful APIs \n" +
                        "Spring Boot中使用Swagger2构建RESTful APIs \nSpring Boot中使用Swagger2构建RESTful APIs \n" +
                        "Spring Boot中使用Swagger2构建RESTful APIs \n" +
                        "Spring Boot中使用Swagger2构建RESTful APIs \n")
                .description("更多Spring Boot相关文章请关注：top.mschen.com/")
                .termsOfServiceUrl("www.baidu.com/")
                .contact(new Contact("mschen博客","top.mschen.com","123456@qq.com"))
                .version("1.0.0")
                .build();
    }
}
